﻿<!DOCTYPE html>
<html lang="en">
<head>
    @* <meta name="viewport" content="width=device-width, initial-scale=1.0">*@
    <meta http-equiv="Pragma" content="no-cache">
    @Styles.Render("~/bootstrapv3/css")

    <link href="@Url.Content("~/Addon/bootstrapv3/css/bootstrap.css")" type="text/css" rel="stylesheet" />

    @Styles.Render("~/css/main")
    @Styles.Render("~/bootstrapv3/css/nonresponsive")



    @Scripts.Render("~/bundles/jquery")
    @Styles.Render("~/jqueryui/css")

    <link href="@Url.Content("~/Content/themes/cupertino/jquery-ui-1.10.3.custom.css")"  type="text/css" rel="stylesheet"/>

    @Scripts.Render("~/jqueryui/js")
    @Scripts.Render("~/bootstrapv3/js")
    @Scripts.Render("~/bundles/modernizr")

    @Styles.Render("~/jqgrid/css")
    @Scripts.Render("~/jqgrid/js")

    @Styles.Render("~/scroll/css")
     <link href="@Url.Content("~/Addon/scrollbar/css/jquery.mCustomScrollbar.css")"  type="text/css" rel="stylesheet"/>    
    @Scripts.Render("~/scroll/js")

    @Scripts.Render("~/others")
    @RenderSection("scripts", required: false)

    <!--[if lt IE 9]>     
         <script src="/Addon/bootstrapv3/js/html5shiv.js"></script>
         <script src="/Addon/bootstrapv3/js/respond.min.js"></script>
    <![endif]-->
    <script>
        function GetCurrentLoginUser(callback) {
            $.ajax({
                url: "/User/GetCurrentLoginUser",
                data: {},
                contentType: 'application/json',
                dataType: "json",
                type: "get",
                success: function (data) {
                    callback(data);
                }
            });
        }

        function toggleOpenNotify() {
            var cls = ($(".notify").attr("class"));
            refreshMessageBoard(function () {
                $(".notify.hide").toggleClass("show");
            });



        }

        function refreshUnviewedMessageCount() {
            $.ajax({
                url: "/Customer/GetUnviewedMessageCount",
                data: {},
                contentType: 'application/json',
                dataType: "json",
                type: "get",
                success: function (data) {

                    if (data > 0)
                        $("#unviewed-msg").css({ 'background-color': 'red' });
                    else
                        $("#unviewed-msg").removeAttr("style");
                    $("#unviewed-msg").text(data);
                }
            });
        }

        function refreshMessageBoard(callback) {
            $.ajax({
                url: "/Customer/MessageBoard",
                data: {},
                contentType: 'text/html',
                dataType: "html",
                type: "get",
                success: function (data) {
                    $(".notify").html(data);
                    callback();
                }
            });
        }

        function listenRequest() {
            refreshUnviewedMessageCount();
            window.setTimeout(function () { listenRequest(); }, 10000);
        }

        $(document).ready(function () {
            listenRequest();
        });

        function openNewProductCategoryWindow() {
            GetCurrentLoginUser(function (data) {
                if (!data || !data.Username || data.Username === '')
                    window.location.href = '/User/Login';
                if (!data.IsAdmin) {
                    window.location.href = '/User/Login';
                }
                $.blockUI();
                $.ajax({
                    url: "/Customer/ProductCategory",
                    data: {},
                    contentType: 'text/html',
                    dataType: "html",
                    type: "get",
                    success: function (data) {
                        $("#changePasswordWindow .modal-body").html(data);
                        $('#changePasswordWindow .modal-title').html("Thêm nhóm sản phẩm");
                        $('#changePasswordWindow').modal({ backdrop: false });

                        $("#changePasswordWindow .modal-dialog").css({ width: 500 });

                        $.unblockUI();
                    },
                    error: function (data) {
                        alert("Yêu cầu đăng nhập lại");
                        $.unblockUI();
                    }
                });

            });
        }

        function changePassword() {
            GetCurrentLoginUser(function (data) {               
                if (!data || !data.Username || data.Username === '')
                    window.location.href = '/User/Login';
               
                $.blockUI();
                $.ajax({
                    url: "/User/ChangePassword",
                    data: {},
                    contentType: 'text/html',
                    dataType: "html",
                    type: "get",
                    success: function (data) {
                        $("#changePasswordWindow .modal-body").html(data);
                        $('#changePasswordWindow .modal-title').html("Thay đổi mật khẩu");
                        $('#changePasswordWindow').modal({ backdrop: false });

                        $("#changePasswordWindow .modal-dialog").css({ width: 500 });

                        $.unblockUI();
                    },
                    error: function (data) {
                        alert("Yêu cầu đăng nhập lại");
                        $.unblockUI();
                    }
                });

            });
        }

        function openHistory(type) {
            var t = type == 0 ? "Lịch sử đăng nhập" : "Lịch sử hoạt động";

            GetCurrentLoginUser(function (data) {
                if (!data || !data.Username || data.Username === '')
                    window.location.href = '/User/Login';
                if (!data.IsAdmin) {
                    window.location.href = '/User/Login';
                }
                $.blockUI();
                $.ajax({
                    url: "/History/ViewHistory/" + type,
                    data: {},
                    contentType: 'text/html',
                    dataType: "html",
                    type: "get",
                    success: function (data) {
                        $("#changePasswordWindow .modal-body").html(data);
                        $('#changePasswordWindow .modal-title').html(t);
                        $('#changePasswordWindow').modal({ backdrop: false });

                        $("#changePasswordWindow .modal-dialog").css({ width: 800 });

                        $.unblockUI();
                    },
                    error: function (data) {
                        alert("Yêu cầu đăng nhập lại");
                        $.unblockUI();
                    }
                });

            });
        }
    </script>
</head>


<body>
    @{   
        var currentUser = Session[NCLCustomerManagement.Common.Constant.Constant.CURRENT_USER]
                           as NCLCustomerManagement.UI.Models.User.AuthenticatedUser;
        var username = currentUser.Username;
        var isAdmin = currentUser.IsAdmin;                       
    }
    @* @RenderSection("nav")*@
    <div class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/Customer">Samnamlinhchi.com</a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        @Html.ActionLink("Khách hàng", "Index", "Home")
                    </li>
                     <li class="dropdown">
                        @Html.ActionLink("Bán hàng", "Index", "Sale")
                    </li>
                    @if (isAdmin)
                    {
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li>@Html.ActionLink("Quản lý User", "Index", "User")</li>
                                <li>@Html.ActionLink("Danh sách sản phẩm","Index","Product")</li>

                                <li><a href="javascript:;" onclick="openNewProductCategoryWindow();">Quản lý nhóm sản phẩm</a></li>

                            </ul>
                        </li>
                    

                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Lịch sử<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="javascript:;" onclick="openHistory(0);">Lịch sử truy cập</a></li>
                                <li><a href="javascript:;" onclick="openHistory(1);">Lịch sử hoạt động của user</a></li>


                            </ul>
                        </li>
                    }

                </ul>
                <ul class="nav navbar-nav navbar-right" style="font-size: 11px;">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Xin chào <b>@username</b>
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="javascript:;" onclick="changePassword();">Đổi mật khẩu</a>

                                <!-- /.modal -->
                            </li>
                            <li>@Html.ActionLink("Đăng xuất", "Logout", "User")</li>


                        </ul>
                    </li>

                    <li style="position: relative;">
                        <a onclick="toggleOpenNotify();" href="#" style="padding: 15px 5px;">Thông báo
                            
                             <span id="unviewed-msg"  class="badge" style="@(ViewBag.UnviewedMessageCount > 0 ? "background-color:red;" : "")">@ViewBag.UnviewedMessageCount</span>

                        </a>
                        <div class="notify hide">
                        </div>
                    </li>

                    <li style="height: 50px;"></li>


                </ul>

            </div>
            <!--/.nav-collapse -->


        </div>
    </div>
    <div class="container">

        @Html.Partial("_ValidationSummary")
        <div id="main">
            <h4 class="title">@RenderSection("title", required: false)</h4>

            @RenderBody()
        </div>
        <!-- Main component for a primary marketing message or call to action -->




    </div>
    <div id="footer" class="container">
        Copyright &copy 
        <a href="http://www.samnamlinhchi.com" target="_blank">samnamlinhchi.com</a>
        <br />
        Designed by <a href="mailto:dinhhungitsoft@gmail.com">dinhhungitsoft</a>
    </div>

    <div id="changePasswordWindow" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Modal title</h4>
                </div>
                <div class="modal-body">
                    <p>One fine body&hellip;</p>
                </div>

            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
</body>
</html>
